package leetcodecompetition.D369;

/**
 * @Author: Siantar
 * @Date: 2023-10-29-11:11
 * @Description: 1.0
 */
public class T100107 {
    public long minIncrementOperations(int[] nums, int k) {
        long[] dp = new long[3];
        for (int i = 0; i < 3; i++) {
            dp[i] = k - nums[i];
            if (nums[i] >= k) {
                for (int j = 0; j <= i; j++) {
                    dp[i] = 0;
                }
            }
        }
        System.out.println(dp[0]+" "+dp[1]+" "+dp[2]);
        for (int i = 3; i < nums.length; i++) {
            long d2t = Math.min(Math.min(dp[0], dp[1]), dp[2]) + Math.max(k - nums[i], 0);
            dp[0] = dp[1];
            dp[1] = dp[2];
            dp[2] = d2t;
            System.out.println(dp[0]+" "+dp[1]+" "+dp[2]);
        }
        return Math.min(Math.min(dp[0], dp[1]), dp[2]);
    }
}
